package com.ctrip.ibu.permissions.security.dto;

import com.ctrip.ibu.permissions.security.security.JwtUser;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

/**
 * description
 *
 * @author r.shi 2020/03/30 1:33
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserDto {
    private Long id;

    private String username;

    private String email;

    private Integer age;

    private LocalDateTime createTime;

    private LocalDateTime updateTime;

    private List<String> roles;

    public UserDto (JwtUser jwtUser){
        this.id = jwtUser.getId();
        this.email = jwtUser.getEmail();
        this.username = jwtUser.getUsername();
        this.roles = jwtUser.getAuthorities().stream().map(authority ->authority.getAuthority().toLowerCase() ).collect(Collectors.toList());
    }


}
